package com.lm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lm.pojo.DocterTag;
import com.lm.pojo.Docter;
import com.lm.pojo.Organization;
import com.lm.pojo.TeamManage;
import com.lm.service.DocterService;
import com.lm.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @dscription:TODO
 * @author32477
 * @date 2025/9/21 21:11
 */
@RestController
@RequestMapping("/docter")
@Api(tags = "医生管理")
@CrossOrigin(origins = "*")
public class DocterController {
    @Autowired
    DocterService docterService;

    /**
     * @description: 查询医生信息
     * @param: docter
     * @return: com.lm.util.ResultUtil<java.util.List<com.lm.pojo.Docter>>
     * @author 32477
     * @date: 2025/9/22 10:48
     */
    @ApiOperation(value = "查询医生信息", httpMethod = "GET", notes = "查询医生信息")
    @GetMapping("/findDocters")
    public ResultUtil<List<Docter>>findDocters(){
        System.out.println("1");
        try{
            return new ResultUtil<>(200,"查询成功",docterService.findDocters());
        }catch (Exception e){
            e.printStackTrace();
            return new ResultUtil<>(500,"查询失败");
        }
    }


    /** 
     * @description: 查找医生列表
     * @param: docter 
     * @return: com.lm.util.ResultUtil<java.util.List<com.lm.pojo.Docter>> 
     * @author 32477
     * @date: 2025/9/22 10:48
     */ 
    @ApiOperation(value = "查询医生列表", notes = "查询医生列表", httpMethod = "POST")
    @PostMapping("/findList")
    public ResultUtil<IPage<Docter>>findList(@RequestBody Docter docter){
        try{
            System.out.println(docter.toString());
            return new ResultUtil<>(200,"查询成功",docterService.findList(docter));
        }catch (Exception e){
            e.printStackTrace();
            return new ResultUtil<>(500,"查询失败");
        }
    }

    /**
     * @description: 添加医生
     * @param: docter
     * @return: com.lm.util.ResultUtil<java.lang.String>
     * @author 32477
     * @date: 2025/9/22 10:48
     */
    @ApiOperation(value = "添加医生", notes = "添加医生", httpMethod = "POST")
    @PostMapping("/addDocter")
    public ResultUtil<String>addDocter(@RequestBody Docter docter){
        try{
            docterService.addDocter(docter);
            return new ResultUtil<>(200,"添加成功");
        }catch (Exception e){
            e.printStackTrace();
            return new ResultUtil<>(500,"添加失败");
        }
    }

    /**
     * @description: 删除医生
     * @param: docterId
     * @return: com.lm.util.ResultUtil<java.lang.String>
     * @author 32477
     * @date: 2025/9/22 10:48
     */
    @ApiOperation(value = "删除医生", notes = "删除医生", httpMethod = "DELETE")
    @DeleteMapping("/deleteDocter")
    public ResultUtil<String>deleteDocter(@RequestParam Integer docterId){
        try{

            docterService.deleteDocter(docterId);
            return new ResultUtil<>(200,"删除成功");
        }catch (Exception e){
            e.printStackTrace();
            return new ResultUtil<>(500,"删除失败");
        }
    }
    /**
     * @description: 修改医生信息
     * @param: docter
     * @return: com.lm.util.ResultUtil<java.lang.String>
     * @author 32477
     * @date: 2025/9/22 10:48
     */
    @ApiOperation(value = "修改医生信息", notes = "修改医生信息", httpMethod = "PUT")
    @PutMapping("/updateDocter")
    public ResultUtil<String>updateDocter(@RequestBody Docter docter){
        try{
            docterService.updateDocter(docter);
            return new ResultUtil<>(200,"修改成功");
        }catch (Exception e){
            e.printStackTrace();
            return new ResultUtil<>(500,"修改失败");
        }
    }
    
    /** 
     * @description: 获取机构信息
     * @param:  
     * @return: com.lm.util.ResultUtil<com.lm.pojo.Organization> 
     * @author 32477
     * @date: 2025/9/22 16:03
     */ 
    @ApiOperation(value = "查询医生编号和名称", notes = "查询医生编号和名称", httpMethod = "GET")
    @GetMapping("/findIdAndName")
    public ResultUtil<List<Organization>>findIdAndName(){
        try{
            return new ResultUtil<>(200,"查询成功",docterService.findDocterList());
        }catch (Exception e){
            e.printStackTrace();
            return new ResultUtil<>(500,"查询失败");
        }
    }

    /**
     * @description: 获取医生团队信息
     * @param:
     * @return: com.lm.util.ResultUtil<com.lm.pojo.TeamManage>
     * @author 32477
     * @date: 2025/9/22 16:03
     */
    @ApiOperation(value = "查询医生团队信息", notes = "查询医生团队信息", httpMethod = "GET")
    @GetMapping("/findTeamList")
    public ResultUtil<List<TeamManage>>findTeamList(){
        try{
            return new ResultUtil<>(200,"查询成功",docterService.findTeamList());
        }catch (Exception e){
            e.printStackTrace();
            return new ResultUtil<>(500,"查询失败");
        }
    }

    /**
     * @description:
     * @param:
     * @return: com.lm.util.ResultUtil<java.lang.Integer>
     * @author 32477
     * @date: 2025/9/22 20:51
     */
    @ApiOperation(value = "查询医生编号", notes = "查询医生编号", httpMethod = "GET")
    @GetMapping("/findLastNumber")
    public ResultUtil<Integer>findLastNumber(){
        try{
            return new ResultUtil<>(200,"查询成功",docterService.findLastNumber());
        }catch (Exception e){
            e.printStackTrace();
            return new ResultUtil<>(500,"查询失败");
        }
    }

    @ApiOperation(value = "查询医生标签", notes = "查询医生标签", httpMethod = "GET")
    @GetMapping("/findTag")
    public ResultUtil<List<DocterTag>>findTag(){
        try{
            return new ResultUtil<>(200,"查询成功",docterService.findTag());
        }catch (Exception e){
            e.printStackTrace();
            return new ResultUtil<>(500,"查询失败");
        }
    }
}
